<template>
	<div class="div1">
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>咨询师管理</el-breadcrumb-item>
			<el-breadcrumb-item>订单管理</el-breadcrumb-item>
		</el-breadcrumb>
	</div>
	<div>
		<div class="div2">
			<span class="spanTop">咨询师名称</span>
			<el-input size="large" v-model="searchName" style="width: 240px" clearable @clear="query"
				placeholder="请输入咨询师名称" />
			<span class="spanTop">用户名</span>
			<el-input size="large" v-model="searchUserName" style="width: 240px" clearable @clear="query"
				placeholder="请输入用户名" />
			<span class="spanTop">收费类别</span>
			<el-input size="large" v-model="searchSort" style="width: 240px" clearable @clear="query"
				placeholder="请输入收费类别" />
			<span class="spanTop">金额</span>
			<el-input size="large" v-model="searchMoney" style="width: 240px" clearable @clear="query"
				placeholder="请输入金额" />
			<el-button @click="query" type="primary" size="large" class="bt1">搜索</el-button>
			<!-- <el-button type="danger" size="large" class="bt1" @click="removeAll">批量删除</el-button> -->
		</div>

		<el-table :data="tableData" style="width:100%; margin-top: 10px;" border
			@selection-change="handleSelectionChange">
			<el-table-column type="selection" />
			<el-table-column fixed prop="id" label="ID" />
			<el-table-column prop="charge.category.categoryName" label="收费类别" />
			<el-table-column prop="charge.price" label="金额" />
			<el-table-column prop="user.username" label="用户名" />
			<el-table-column prop="consultant.name" label="咨询师名称" />
		<!-- 	<el-table-column fixed="right" label="操作" width="200">
				<template #default="scope">
					<el-button type="danger" @click="remove(scope.row)">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>

		<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[5, 10,15, 20]"
			:size="size" layout="total, sizes, prev, pager, next, jumper" :total=" total"
			@size-change="handleSizeChange" @current-change="handleCurrentChange" v-if="total !=0" />
	</div>
</template>
<script setup>
	import {
		onMounted,
		ref,
		reactive,
		computed,
		watch
	} from 'vue'
	import {
		ElMessage,
		ElMessageBox
	} from 'element-plus'
	import {
		Plus
	} from '@element-plus/icons-vue'
	import {
		getCurrentInstance
	} from 'vue';

	const axios = getCurrentInstance().appContext.config.globalProperties.axios
	const tableData = ref([])
	const currentPage = ref(1) // 当前页
	const pageSize = ref(10) // 每页显示条目数
	const size = 'default' // 分页大小
	const total = ref(0)
	const searchName = ref('')
	const searchUserName = ref('')
	const searchSort = ref('')
	const searchMoney = ref('')

function query() {
	axios.get(
		`consultationOrder/page?name=${searchName.value}&username=${searchUserName.value}&categoryName=${searchSort.value}&price=${searchMoney.value}&pageNum=${currentPage.value}&pageSize=${pageSize.value}`,
	).then(resp => {
		tableData.value = resp.data.list;
		total.value = resp.data.total
		console.log(resp.data)
	})
}
	const handleSizeChange = (val) => {
		pageSize.value = val;
		query();
	}
	const handleCurrentChange = (val) => {
		currentPage.value = val
		query();
	}
	// const remove = (row) => {
	// 	console.log('当前行的数据', row);
	// 	ElMessageBox.confirm(
	// 			'此操作将永久删除该文件, 是否继续?',
	// 			'Warning', {
	// 				confirmButtonText: '确认',
	// 				cancelButtonText: '取消',
	// 				type: 'warning',
	// 			}
	// 		)
	// 		.then(() => {
	// 			axios.delete(`consultationOrder/${row.id}`).then((resp) => {
	// 				console.log('删除后：', resp);
	// 				if (resp.code == 200) {
	// 					ElMessage({
	// 						message: '删除成功',
	// 						type: 'success',
	// 					})
	// 				} else {
	// 					ElMessage.error('删除失败')
	// 				}
	// 			}).finally(() => {
	// 				query();
	// 			});

	// 		})
	// 		.catch(() => {
	// 			ElMessage({
	// 				type: 'info',
	// 				message: '取消删除',
	// 			})
	// 		})

	// }
	// const multipleSelection = ref([])
	// const handleSelectionChange = (val) => {
	// 	multipleSelection.value = val.map(item => {
	// 		return item.id
	// 	})
	// 	console.log(multipleSelection.value);
	// }
	// const removeAll = () => {
	// 	if (multipleSelection.value.length === 0) {
	// 		ElMessage.warning('请至少选择一项');
	// 		return;
	// 	}
	
	// 	ElMessageBox.confirm(
	// 		'此操作将永久删除该文件, 是否继续?',
	// 		'Warning', {
	// 			confirmButtonText: '确认',
	// 			cancelButtonText: '取消',
	// 			type: 'warning',
	// 		}
	// 	).then(() => {
	// 		// 转换为数字数组
	// 		const idsToDelete = multipleSelection.value.map(id => Number(id));
	
	// 		// 使用data传递请求体
	// 		axios.delete('consultationOrder', {
	// 			data: idsToDelete,
	// 			headers: {
	// 				'Content-Type': 'application/json'
	// 			}
	// 		}).then(resp => {
	// 			if (resp.code == 200) {
	// 				ElMessage.success(resp.data || '删除成功');
	// 			} else {
	// 				ElMessage.error(resp.data || '删除失败');
	// 			}
	// 		}).catch(error => {
	// 			ElMessage.error(`删除失败: ${error.response?.data || error.message}`);
	// 		}).finally(() => {
	// 			query();
	// 		});
	// 	}).catch(() => {
	// 		ElMessage({
	// 			type: 'info',
	// 			message: '取消删除',
	// 		});
	// 	});
	// };
	onMounted(() => {
		query();
	})
</script>
<style scoped>
	.spanTop {
		margin: 0 10px;
		color: #696a6e;
	}

	.avatar-uploader .el-upload {
		border: 1px dashed var(--el-border-color);
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
		transition: var(--el-transition-duration-fast);
	}

	.avatar-uploader .el-upload:hover {
		border-color: var(--el-color-primary);
	}

	.el-icon.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		text-align: center;
	}

	.bt1 {
		margin-top: 10px;
		margin-left: 10px;
	}

	.div1 {
		border-bottom: 1px solid #eeeeee;
		width: 100%;
		height: 30px;
		padding-top: 15px;
		padding-left: 15px;
	}

	.div2 {
		padding-top: 15px;
	}

	.el-table {
		margin-left: 10px;
	}
	.el-pagination{
		margin-top: 10px;
		margin-left: 10px;
	}
</style>